﻿// See https://aka.ms/new-console-template for more information

using ChangeLog.CommunityToolkit;

class Program
{
    static void Main(string[] args)
    {
        var codePath = string.Empty;
        if (args.Any())//cmd传参
            codePath = args[0];
        else
            codePath = new CmdRunner().PrintDoc("cd");
        if (!Directory.Exists(codePath))
        {
            Console.WriteLine($"代码路径不存在：{codePath}");
            return;
        }
        Console.WriteLine($@"CHANGELOG.md生成路径：{codePath}");
        var git = new GitRunner("git", codePath);
        var log = git.Run("log --decorate=full");
        var mdStr = ChangeLogHelper.BuildChangLog(log);
        var chagelogPath = $@"{codePath}\CHANGELOG.md";
        Console.WriteLine("===================================CHANGELOG START===================================");
        Console.WriteLine(mdStr);
        Console.WriteLine("===================================CHANGELOG   END===================================");
        File.WriteAllText(chagelogPath, mdStr);
        if (File.Exists(chagelogPath))
            Console.WriteLine($"CHAGELOG已生成：{chagelogPath}");
        else
            Console.WriteLine("CHAGELOG生成失败");
        Console.WriteLine("按 Enter 退出程序……");
        Console.ReadLine();
    }
}



